<?php
namespace app\common\model;

class ChatMsg extends Common
{
    protected $autoWriteTimestamp = true;
    protected $createTime = 'ctime';
    /**
     * 获取直播视频
     */
    public function mgsList($data){
        $list=$this->where(['from_uid'=>$data['id'],'to_uid'=>$data['uid']])->whereOr(['from_uid'=>$data['uid'],'to_uid'=>$data['id']])->page($data['page'],$data['limit'])->select();
        foreach($list as $k=>$v){
            $list[$k]['ctime']=time_ago($v['ctime']);
        }
        $userModel = new User();
        $info=$userModel->getUserInfo($data['uid']);
        return ['info'=>$info['data'],'list'=>$list];
    }

    /**
     * 聊天记录表关联
     * @return [type] [description]
     */
    public function chat(){
        return $this->hasMany('ChatLog','msg_id','id');
    }

}
